const mysql = require('mysql')
const option = require('./config')

// 创建数据库
const connection = mysql.createConnection(option)

// 开始连接
connection.connect((err) => {
    if (err) {
        console.log('数据库连接失败');
    }
})

module.exports = {
    query: (sql, params) => {
        console.log(params);
        return new Promise((resolve, reject) => {
            connection.query(sql, params, (err, result) => {
                if (err) {
                    console.log('数据操作失败');
                    reject(err)
                    return
                } else {
                    resolve(result)
                }
            })
        })
    }
}